/**
 * loading 插件
 * create by Ryan
 */
import Vue from 'vue';
import './loading.scss'

export default class LoadingClass {

    constructor() {
        // 缓存vue实例
        this.instance = null;
        // 缓存mount后的实例
        this.instanceEl = null;
        // 缓存#jh-main
        this.app = null
    }

    /** open loading*/
    open() {
        if (!this.instance) {
            this.instance = new Vue({
                template: '<div class="g-loading-mark">   ' +
                    '<Spin fix>\n' +
                    '<Icon type="load-c" size=18 class="demo-spin-icon-load"></Icon>\n' +
                    '                <div>加载中</div>\n' +
                    '</Spin></div>'
            });
        }
        this.instanceEl = this.instance.$mount();
        if(!this.app){
            this.app = document.getElementById('jh-main');
        }
        this.app.appendChild(this.instanceEl.$el);
    }

    /** close loading*/
    close() {
        this.instanceEl && this.app.removeChild(this.instanceEl.$el);
        this.instanceEl = null;
        this.instance && this.instance.$destroy();
    }
}
